/*
https://leetcode.cn/problems/minimum-size-subarray-sum/
LC209. 长度最小的子数组
*/
class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int l=0,j=0,len=nums.size()+1;
        long long sum=0;
            while(j<nums.size()){
                sum=sum+nums[j];
                if(sum>=target){
                    len=min(len,j-l+1);
                    while(sum>=target){
                        sum-=nums[l];
                        len=min(len,j-l+1);
                        ++l;
                    }
                }
               ++j;
            }
            if(len==nums.size()+1) return 0;
        return len;
    }
};